<template>
  <div class="app-container">
    <el-card class="box-card">
      <el-form :inline="true" :model="listQuery">
        <el-form-item label="">
          <el-date-picker
            v-model="listQuery.search_date"
            type="month"
            format="yyyy-MM"
            value-format="yyyy-MM"
            size="small"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click.native="handleFilter"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        :data="datas"
        border
        v-loading="listLoading"
        fit
        size="small"
        highlight-current-row
      >
        <el-table-column
          type="index"
          label="#"
          align="center"
          width="60px;"
        ></el-table-column>
        <el-table-column align="left" label="项目名称" width="260px">
          <template slot-scope="scope">
            <div v-if="scope.row.code.length==2" style="font-size: 16px;">{{ scope.row.name }}</div>
            <div v-else-if="scope.row.code.length==4" style="font-size: 14px;text-align:center">{{ scope.row.name }}</div>
            <div v-else style="text-align:right;padding-right: 20px;">{{ scope.row.name }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="本月合计(元)" width="200px">
          <template slot-scope="scope">{{ scope.row.total_money.toFixed(2) }}</template>
        </el-table-column>
        <el-table-column align="center" label="本年累计(元)" width="200px">
          <template slot-scope="scope">{{ scope.row.year_total_money.toFixed(2) }}</template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { formatDateTime } from "@/utils/datetime";
import { getProfitStats } from "@/api/fundbill";

export default {
  name: "Profit",
  data() {
    return {
      datas: [],
      fontSize: "fontSize",
      listLoading: true,
      listQuery: {
        search_date: formatDateTime(new Date(), "yyyy-MM"),
      },

      tableColumns: [
        {
          key: "name",
          title: "项目名称",
          align: "left",
          headerAlign: "left",
          width: "260px",
        },
        {
          key: "total_money",
          title: "本月合计(元)",
          width: "200px",
          align: "center",
          headerAlign: "center",
        },
        {
          key: "year_total_money",
          title: "本年累计(元)",
          width: "200px",
          align: "center",
          headerAlign: "center",
        },
      ],
    };
  },
  computed: {
    ...mapGetters(["uid"]),
  },
  components: {},
  mounted() {
    this.getProfStats();
  },
  methods: {
    getProfStats() {
      this.listLoading = true;
      getProfitStats(this.listQuery)
        .then((res) => {
          console.log(res);
          this.datas = res;
          this.listLoading = false;
        })
        .catch((error) => {
          console.log(error.message);
          this.$message.error("获取数据失败");
          this.listLoading = false;
        });
    },

    dataFormatter(row, column, cellValue, index) {
      if (
        column.property === "total_money" ||
        column.property === "year_total_money"
      ) {
        return cellValue.toFixed(2);
      } else {
        return cellValue;
      }
    },
    // 查询
    handleFilter() {
      this.getProfStats();
    },
  },
};
</script>

<style lang='scss' scoped>
.app-container {
  .item {
    margin-top: 8px;
  }

}
</style>